<?php
/**
 * 
 * @author guibinyu
 * @date 2017-06-15 04:14:50
 */
class Menu   
{
    
   private $Wechat;
   public function __construct($Wechat)
    {
        $this->Wechat = $Wechat;
    }
    /**
     * 创建菜单
     */
    public function createMenu()
    {
        $menu = array(
            0 => array(
                'name' => '推送消息',
                'sub_button' =>array(
                    array(
                     'name' => '被动图文',
                    'type' => 'click',
                    "key" => "V1002_NEWS",
                ),
                array(
                     'name' => '素材图文',
                    'type' => 'media_id',
                    "media_id" => "tm0D20ZrIxNCja3xm6dVBYVj_afcY7_6wiJtc1haObI",
                ),
                array(
                     'name' => '素材图片',
                    'type' => 'media_id',
                    "media_id" => "tm0D20ZrIxNCja3xm6dVBSNGr9jt1rBhgF_b3sBTZv0",
                ),
                array(
                     'name' => '素材音乐',
                    'type' => 'media_id',
                    "media_id" => "tm0D20ZrIxNCja3xm6dVBdvuVG1U1uCQYs5TSfod75g",
                ),
                array(
                     'name' => '素材视频',
                    'type' => 'media_id',
                    "media_id" => "tm0D20ZrIxNCja3xm6dVBWLzSXH5XJ0P4NksH0T8rHE",
                ),
//                     array(
//                     'name' => '图文消息',
//                    'type' => 'view_limited',
//                    "key" => "MEDIA_ID2",
//                ),
            )
            ),
            1 => array(
                'name' => '自动回复',
                'sub_button' =>array(
                    array(
                    "type" => "view",
                    "name"=> "搜索",
                    "url"=> "http://www.soso.com/"
                ),
                    array(
                    "type" => "pic_sysphoto",
                    "name" => "系统拍照发图",
                    "key" => "rselfmenu_1_0",
                ),
                     array(
                     "type" => "pic_photo_or_album",
                    "name" => "拍照或者相册发图",
                    "key" => "rselfmenu_1_1",
                ),
                     array(
                     "type" => "pic_weixin",
                    "name" => "微信相册发图",
                    "key" => "rselfmenu_1_2",
//                ),
                )
            )
            ),
            2 => array(
                'name' => '扫码与位置',
                'sub_button' =>
                
                array(
                    array(
                       "type"=> "scancode_push", 
                       "name"=> "扫码推事件", 
                       "key"=> "rselfmenu_0_1", 
                    ),
                     array(
                    "type" =>  "scancode_waitmsg", 
                    "name"=>  "扫码带提示", 
                    "key"=>  "rselfmenu_0_0", 
                ),
                    array(
                    'type' => 'location_select',
                     'name' => '发送位置',
                    "key" => "rselfmenu_2_0",
                ),
                )
            ),
        );
        
        $menu = isset($_POST['param']) && !empty($_POST['param']) ? json_decode($_POST['param'],true) : $menu;
        $menus['button'] = $menu ;//适配微信菜单要求,多套一层
        $result = $this->Wechat->Menu->createMenu($menus);
        return $result;
    }
    /**
     * 获取菜单
     */
    public function getMenu()
    {
        $result = $this->Wechat->Menu->getMenu();
        return $result;
    }
    public function __call($name, $arguments)
    {
        exit("Test does not have [{$name}] method !");
    }
     
     
//index, view, create, update, delete, options
}